using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace G4KFramework
{
    class GTimeLine
    {
        private long _timeLine = 0;
        private long _timeBegin = 0;

        private Dictionary<long, EventHandler> _callbacks = new Dictionary<long,EventHandler>();

        public GTimeLine()
        {
        }

        public void Update()
        {
            _timeLine = DateTime.Now.Ticks - _timeBegin;

            foreach (KeyValuePair<long, EventHandler> eventHandler in _callbacks)
            {
                if (eventHandler.Key >= _timeLine)
                {
                    eventHandler.Value.Invoke(this, new EventArgs());
                    _callbacks.Remove(eventHandler.Key);
                }
            }
        }

        public void RegisterEvent(long timeSpan, EventHandler eventHandler)
        {
            _callbacks.Add(timeSpan, eventHandler);
        }

        public void Begin()
        {
            _timeBegin = DateTime.Now.Ticks;
        }
    }
}
